package com.example.webdownloadserver.service;

import com.example.webdownloadserver.core.excel.ExcelExportIface;
import com.example.webdownloadserver.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Map;

/**
 * @ClassName DownloadUserService
 * @Description TODO
 * @Auth ying.xiao
 * @Date 2021/8/10
 * @Version 1.0.0
 */
@Service
public class DownloadUserService implements ExcelExportIface {

    @Autowired
    private UserDao userDao;

    /**
     * 此方法可以使用mybatis实现持久化查询，关注param动态参数
     * @param param
     * @return
     * @throws Exception
     */
    @Override
    public int queryListCount(Map<String, Object> param) throws Exception {
        return (int) userDao.count();
    }

    /**
     * 此方法可以使用mybatis实现持久化查询，关注param动态参数
     * @param param
     * @param page
     * @param limit
     * @return
     * @throws Exception
     */
    @Override
    public Collection<?> queryListPage(Map<String, Object> param, Integer page, Integer limit) throws Exception {
        Sort sort = Sort.by(Sort.Direction.DESC,"id");
        Pageable pageable=  PageRequest.of(page-1, limit,sort);
        return userDao.findAll(pageable).getContent();
    }
}
